package com.luhuiguo.gwt.mvp.dispatcher.client.gin;

import com.google.gwt.inject.client.Ginjector;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.luhuiguo.gwt.mvp.dispatcher.client.DefaultExceptionHandler;
import com.luhuiguo.gwt.mvp.dispatcher.client.DispatcherAsync;
import com.luhuiguo.gwt.mvp.dispatcher.client.ExceptionHandler;
import com.luhuiguo.gwt.mvp.dispatcher.client.StandardDispatcherAsync;

/**
 * This module binds the {@link DispatcherAsync} to
 * {@link StandardDispatchAsync}. For simple cases, just add this as a
 * \@GinModule in your {@link Ginjector} instance.
 * <p/>
 * If you want to provide a custom {@link ExceptionHandler} just call
 * <code>install( new StandardDispatchModule( MyExceptionHandler.class )</code>
 * in another module.
 * 
 * @author LuHuiguo
 * @version $Id: StandardDispatcherModule.java 8 2009-12-25 03:02:51Z luhuiguo $
 */
public class StandardDispatcherModule extends AbstractDispatcherModule {

    /**
     * Constructs a new GIN configuration module that sets up a
     * {@link com.luhuiguo.gwt.mvp.dispatcher.client.DispatcherAsync}
     * implementation, using the
     * {@link com.luhuiguo.gwt.mvp.dispatcher.client.DefaultExceptionHandler}.
     */
    public StandardDispatcherModule() {
        this(DefaultExceptionHandler.class);
    }

    public StandardDispatcherModule(Class<? extends ExceptionHandler> exceptionHandlerType) {
        super(exceptionHandlerType);
    }

    @Provides
    @Singleton
    protected DispatcherAsync provideDispatcherAsync(ExceptionHandler exceptionHandler) {
        return new StandardDispatcherAsync(exceptionHandler);
    }

}
